<template>
	<view class="apply_for_tixian">
		<view class="apply_for_tixian_title">
			<uni-nav-bar left-icon="left" :border="false" fixed color="#fff" background-color="#8D84FF" title="申请提现"
				@clickLeft="back" />
		</view>
		<view class="boxs">
			<view class="apply_for_tixian_box">
				<view class="apply_for_tixian_box_top">
					<view class="apply_for_tixian_box_top_title">
						<view>提现数量</view>
						<view @click="gotoTixianrecordFun()">提现记录</view>
					</view>
					<view class="apply_for_tixian_box_top_input">
						<span>￥</span><input type="number" v-model="money" placeholder="请输入提现金额" />
						<button style="font-size: 28rpx;background-color:#8D84FF;color: #fff;"
							@click="request_withdrawal()">申请提现</button>
					</view>
					<view class="apply_for_tixian_box_top_num">
						可提现数量<view class="num">{{e.shoyi === undefined?res.credit:e.shoyi}}</view>
					</view>
				</view>
			</view>
			<view class="apply_for_tixian_bottom">
				<view class="apply_for_tixian_bottom_" v-if="bankres">
					银行信息
					<view class="apply_for_tixian_bottoms">
						开户名称：{{bankres.accountName}}
					</view>
					<view class="apply_for_tixian_bottoms">
						开户账号：{{bankres.bankCardNo}}
					</view>
					<view class="apply_for_tixian_bottoms">
						开户银行：{{bankres.bankname}}
					</view>
					<view class="apply_for_tixian_bottoms">
						开户网点：{{bankres.bankbranch}}
					</view>
				</view>

				<view class="apply_for_tixian_bottom_" v-else @click="gotoFun()">
					添加银行卡
				</view>





				<!-- <radio-group class="bankBind_box" @change="radioChange">
					<uni-card :is-shadow="false" class="bankBind_box_item" v-for="(item,index) in my_bank_list"
						:key="index">
						<view class="bankBind_box_item_box">
							<view class="bankBind_box_item_left" style="width: 60%;">
								<h3>{{item.bankname}}</h3>
								<span>{{item.acc_no}}</span>
							</view>
							<view class="bankBind_box_item_right" style="width: 40%;">
								<radio style="transform:scale(0.7);margin: 0 20rpx;" :value="`${index}`" color="red"
									:checked="item.isdefault === '1'" />选择银行
							</view>
						</view>
					</uni-card>
				</radio-group> -->
			</view>
		</view>

		<!-- <view class="apply_for_tixian_button">
			<button class="apply_for_tixian_button_an" @click="request_withdrawal()">
				申请提现
			</button>
		</view> -->
	</view>
</template>

<script>
	import {
		member_withdraw,
		member_withdraw_submit,
		api_index_show_zishanghu_info,
		member_my_wallet
	} from '@/api/wallet.js'
	export default {
		data() {
			return {
				openid: '',
				e: '',
				money: '',
				res: '',
				my_bank_list: '',
				select: '',
				bankres: '',
				my_walletres: ''
			};
		},
		onLoad(e) {
			console.log(e);
			this.e = e;
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data;
					this.showmember_my_wallet();

				},
				fail: () => {
					uni.navigateTo({
						url: '/pages/login/login'
					});
				}
			});
		},
		methods: {
			gotoTixianrecordFun() {
				uni.navigateTo({
					url: `/pages/wallet/Tixianrecord/Tixianrecord?id=${this.my_walletres.id}`
				})
			},
			async showmember_my_wallet() {
				let data = await member_my_wallet(this.openid);
				for (let i in data.escrow) {
					console.log(data.escrow[i]);
					this.my_walletres = data.escrow[i]
				}
				this.showmember_withdrawFun();
				this.api_index_show_zishanghu_infoFun();
			},
			gotoFun() {
				uni.navigateTo({
					url: `/pages/member/bankBind/bankBind?escrow_id=${this.my_walletres.id}`
				})
			},
			async api_index_show_zishanghu_infoFun() {
				let data = await api_index_show_zishanghu_info(this.openid);
				this.bankres = data.info;
			},
			async request_withdrawal() {
				if (this.money === '') {
					this.showinteraction('请输入提现金额');
					return
				}
				let up = {
					openid: this.openid,
					applytype: 4,
					realname: this.bankres.accountName,
					bankcard: this.bankres.bankCardNo,
					bankcard1: this.bankres.bankCardNo,
					bankname: this.bankres.bankname,
					money: this.money,
					bankbranch: this.bankres.bankbranch,
					bankbranch1: '',
					bankbranch3: '',
					accountarea: ' -请选择地区 -',
					escrow_id: this.my_walletres.id,
					type: this.e.type,
					shop_id: this.my_walletres.id === undefined ? '' : this.my_walletres.id,
				}
				let data = await member_withdraw_submit(up);
				if (data.status === 1) {
					this.showinteraction('提现发起成功，请等待审核打款');
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/wallet/wallet'
						})
					}, 2000)
				}
			},
			//提示
			showinteraction(title, icon = 'none') {
				uni.showToast({
					title,
					icon,
					duration: 2000,
					mask: false
				})
			},
			radioChange(e) {
				this.select = this.my_bank_list[e.detail.value];
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			async showmember_withdrawFun() {
				let up = {
					openid: this.openid,
					escrow_id: this.my_walletres.id,
					type: this.e.type
				}
				let data = await member_withdraw(up);
				this.res = data;
				console.log(data);
				if (data.error !== 1) {
					this.my_bank_list = data.my_bank_list;
					// for (let i = 0; i < data.my_bank_list.length; i++) {
					// 	if (this.my_bank_list[i].isdefault === '1') {
					// 		this.select = data.my_bank_list[i];
					// 	}
					// 	console.log(this.select);
					// }
				}
			}
		}
	}
</script>

<style lang="scss">
	.bankBind_box_item {

		.bankBind_box_item_box {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.bankBind_box_left {
				// width: 100%;
				display: flex;
				align-items: center;
				flex: 1;

				.bankBind_box_left_text {
					padding: 0 20rpx;
				}
			}

			.bankBind_box_right {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: flex-end;
				flex: 1;

				image {
					width: 34rpx;
					height: 34rpx;
				}

				.center {
					display: flex;
					align-items: center;
				}
			}
		}
	}

	.apply_for_tixian {
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;

		.boxs {
			width: 100%;
			flex: 1;
			overflow: auto;
		}

		.apply_for_tixian_title {
			width: 100%;
			padding-top: var(--status-bar-height);
			background-color: #8D84FF;
		}

		.apply_for_tixian_box {
			width: 100%;
			height: 400rpx;
			padding: 50rpx 30rpx;

			.apply_for_tixian_box_top {
				width: 100%;
				// height: 238rpx;
				padding: 0 20rpx;
				background-color: #fff;
				border-radius: 30rpx;
				box-shadow: 0 0 10rpx 4rpx #ccc;

				.apply_for_tixian_box_top_title {
					width: 100%;
					padding: 20rpx 24rpx;
					display: flex;
					justify-content: space-between;
					font-size: 28rpx;
				}

				.apply_for_tixian_box_top_input {
					width: 100%;
					height: 80rpx;
					border-bottom: 1rpx solid #eee;
					padding: 10rpx 20rpx;
					display: flex;
					align-items: center;
					margin-bottom: 10rpx;
					// font-size: 44rpx;

					span {
						line-height: 80rpx;
						font-size: 44rpx;
						font-weight: 555;
					}

					input {
						// width: 80%;
						flex: 1;
						margin-left: 20rpx;
						font-size: 40rpx;
						height: 100%;
						font-weight: 400;
					}
				}

				.apply_for_tixian_box_top_num {
					height: 80rpx;
					line-height: 80rpx;
					margin-left: 20rpx;
					color: #555;
					display: flex;
					font-size: 28rpx;

					.num {
						padding: 0 40rpx;
					}
				}
			}
		}

		.apply_for_tixian_bottom {
			padding: 0 30rpx;

			.apply_for_tixian_bottom_ {
				width: 100%;
				background-color: #fff;
				box-shadow: 0 0 5px 2px #ccc;
				border-radius: 20rpx;
				padding: 30rpx;

				.apply_for_tixian_bottoms {
					line-height: 80rpx;
					font-size: 28rpx;
				}
			}
		}
	}

	.apply_for_tixian_button {
		width: 100%;
		padding: 40rpx 20rpx;

		.apply_for_tixian_button_an {
			width: 100%;
			height: 100rpx;
			border-radius: 50rpx;
			border-radius: none;
			background-color: rgb(164, 11, 11);
			color: #fff;
		}
	}
</style>